package Data_IO.data_transformation;

import java.io.*;
import com.alibaba.fastjson.*;

public class File2JsonArray {

    /**
     *
     * @param pathName
     * @return JSONArray
     * @throws IOException
     */
    public static JSONArray file2json(String pathName) throws IOException{

        JSONArray jsonArray = new JSONArray();
        StringBuilder result = new StringBuilder();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    new FileInputStream(pathName), "UTF-8"));
            String s = null;
            while ((s = br.readLine()) != null) {// Use the readLine method to read one line at a time
                result.append(System.lineSeparator() + s);
            }
            br.close();
            jsonArray = JSONArray.parseArray(result.toString());//Convert a file's String type to JSONArray format.

        } catch (Exception e) {//If an exception is encountered, return it.
            e.printStackTrace();
        }

        return jsonArray;
    }
}
